package me.sdevil507.org.repository;

import me.sdevil507.org.po.OrgDeptPo;
import me.sdevil507.supports.jpa.BaseJpaDslRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * 机构部门表[OrgDeptRepository]
 *
 * @author sdevil507
 * created on 2020-06-24 14:29:16
 */
public interface OrgDeptRepository extends BaseJpaDslRepository<OrgDeptPo, Long> {

    /**
     * 逻辑删除
     *
     * @param id 机构id
     */
    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update OrgDeptPo a set a.deleted=true where a.id=:id")
    void logicDelete(@Param("id") Long id);

    OrgDeptPo findOrgDeptPoByOrg_IdAndDeletedAndItIsRoot(Long id, boolean isDel, boolean isRoot);

    OrgDeptPo findOrgDeptPoByTitleAndDeletedIsFalse(String title);
}